package cn.edu.scau.cmi.liyunlin.abstractFactory.factory;

import cn.edu.scau.cmi.liyunlin.abstractFactory.domainAbstractClass.*;
import cn.edu.scau.cmi.liyunlin.abstractFactory.domainInterface.Aonong;
import cn.edu.scau.cmi.liyunlin.abstractFactory.domainInterface.Tianbang;
import cn.edu.scau.cmi.liyunlin.abstractFactory.domainInterface.Wens;

import javafx.event.ActionEvent;
import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.liyunlin.abstractFactory.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;


import javafx.scene.control.TextArea;

import javafx.scene.control.ChoiceBox;

public class AbstractFactoryController implements Initializable  {
	@FXML
	private ChoiceBox<String> company;
	@FXML
	private ChoiceBox<String> meat;
	@FXML
	private Button output;
	@FXML
	private TextArea msg;

	ObservableList<String> companys = FXCollections.observableArrayList(Wens.brand, Tianbang.brand, Aonong.brand);
	ObservableList<String> meats = FXCollections.observableArrayList("Pork", "Beef", "Chicken");

	@Override
	public void initialize(URL arg0, ResourceBundle arg1) {
		// TODO Auto-generated method stub
		company.setItems(companys);
		meat.setItems(meats);
	}

	public void outputBtn(ActionEvent event) {
		String companyName = (String) company.getValue();
		String meatName = (String) meat.getValue();	
		//选择工厂
		AbstractFactory factory = null;
		switch(companyName) {
		case "Wens":
			factory = new WensFactory();break;
		case "Tianbang":
			factory = new TianbangFactory();break;
		case "Aonong":
			factory = new AonongFactory();break;
		}
		
		//选择产品
		ConsumerMeatChoose product = null;
		switch(meatName) {
		case "Pork":
			product = factory.creatPork();
			msg.setText(msg.getText() + factory.creatPork().toString() + "\n");
			break;
		case "Beef":
			product = factory.creatBeef();
			msg.setText(msg.getText() + factory.creatBeef().toString() + "\n");
			break;
		case "Chicken":
			product = factory.creatChicken();
			msg.setText(msg.getText() + factory.creatChicken().toString() + "\n");
			break; 
		}
		
	}
	
}


